package com.jcl.recruit.api.resume.controller;

import com.jcl.recruit.core.web.utils.RequestUtils;
import com.jcl.recruit.log.model.ResumeLog;
import com.jcl.recruit.resume.service.ResumeOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api")
public class ResumeLogController {

    @Autowired
    private ResumeOperateService resumeOperateService;

    /**
     * 查询简历历史记录
     *
     * @param resume_id
     * @return
     */
    @RequestMapping("/resumelog/find")
    public Map<String, Object> resumeLogFind(Integer resume_id) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("type", "success");
        map.put("message", "执行成功");
        List<Map<String, Object>> resumeLogVos = resumeOperateService.selectResumeLogsByResumeId(resume_id);
        map.put("resumeLogs", resumeLogVos);
        map.put("total", resumeLogVos.size());
        return map;
    }

    /**
     * 保存日志简历
     *
     * @param entity
     * @return
     */
    @RequestMapping("/resumelog/save")
    public Map<String, Object> resumelogSave(@RequestBody Map<String, String> entity) {
        Map<String, Object> map = new LinkedHashMap<>();

        ResumeLog resumeLog = new ResumeLog();
        resumeLog.setCreatetime(new Date());
        resumeLog.setResumeId(Integer.valueOf(entity.get("resume_id")));
        resumeLog.setLog(entity.get("log"));
        resumeLog.setUserId(Integer.valueOf(RequestUtils.getUserId()));
        resumeOperateService.insert(resumeLog);
        entity.put("id", resumeLog.getId().toString());
        map.put("type", "success");
        map.put("message", "执行成功");
        map.put("resumeLog", entity);
        return map;
    }


}
